package cn.com.lyj6851.common.validate.sms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import cn.com.lyj6851.common.properties.SecurityConstants;
import cn.com.lyj6851.common.validate.AbstractValidateCodeProcessor;
import cn.com.lyj6851.common.validate.code.ValidateCode;

/**
 * 短信验证码处理器
 */
@Component
public class SmsValidateCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    /**
     * 短信验证码发送器
     */
    @Autowired
    private SmsCodeSender smsCodeSender;

    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
        smsCodeSender.smsCodeSend(mobile, validateCode.getCode());//执行发送短信
    }

}